package com.cskaoyan.service.impl;

import com.cskaoyan.bean.Permission;
import com.cskaoyan.bean.PermissionExample;
import com.cskaoyan.mapper.PermissionMapper;
import com.cskaoyan.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PROJECT_NAME: market_34th
 * @DESCRIPTION:
 * @Author: qiu
 * @DATE: 2021/10/20 18:35
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public List<String> queryPermsByRoleIds(List<Integer> roleIds) {
        return permissionMapper.queryPermsByRoleIds(roleIds);
    }

    @Override
    public void updatePermsByRoleId(Integer roleId, List<String> permissions) {

        // 1.删除当前角色拥有的权限
        PermissionExample example = new PermissionExample();
        PermissionExample.Criteria criteria = example.createCriteria();
        criteria.andRoleIdEqualTo(roleId);
        permissionMapper.deleteByExample(example);

        // 2.新增当前角色的权限
        permissionMapper.insertPermsByRoleId(roleId, permissions);

    }
}
